package com.example.easyexcel.controller;

import com.alibaba.fastjson.JSON;
import com.example.easyexcel.listener.ExcelListener;
import com.example.easyexcel.model.UserModel;
import com.example.easyexcel.model.qianduoduo.ComparedModel;
import com.example.easyexcel.model.qianduoduo.NotSameModel;
import com.example.easyexcel.model.qianduoduo.SameModel;
import com.example.easyexcel.strategy.CustomCellStyleStrategy;
import com.example.easyexcel.strategy.CustomColumnWidthStrategy;
import com.example.easyexcel.zhenzhen.ExcelModel;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

import static com.alibaba.excel.EasyExcelFactory.read;
import static com.alibaba.excel.EasyExcelFactory.write;

public class ZhenController {
    public static void main(String[] args) {
//        readExcel();
        readExcel1100();
    }
    public static void writeExcel(){
//        List<UserModel> userModels = getUserModels();
//        String fileName = "D:\\dangwen1\\Desktop\\excel-test.xlsx";
//        write(fileName, UserModel.class).sheet().head(UserModel.class)
//                .registerWriteHandler(new CustomColumnWidthStrategy())
//                .registerWriteHandler(new CustomCellStyleStrategy()).doWrite(userModels);
    }

    public static void readExcel(){
        int num = 0;
        int lineNum = 0;
        List<ExcelModel> singleList = new ArrayList<>();
        String fileName = "C:\\Users\\hp\\Desktop\\02工作表格：钱真真1-1100(1).xlsx";
        ExcelListener<ExcelModel> excelListener = new ExcelListener<>();
        read(fileName, ExcelModel.class, excelListener).sheet().doRead();
        List<ExcelModel> dataList = excelListener.getDataList();
        for (ExcelModel excelModel : dataList) {
            lineNum++;
            if (lineNum == 1101){
                break;
            }
            String term = excelModel.getTerm();
            String clinicalFeature = excelModel.getClinicalFeature();
            if (hasKeyWord(term) || hasKeyWord(clinicalFeature)){
                excelModel.setHasDoubt("存疑");
                num++;
                singleList.add(excelModel);
            } else {
                excelModel.setHasDoubt("无");
            }
        }
        System.out.println("存疑数量："+num);
        String writeFileName = "C:\\Users\\hp\\Desktop\\copy工作表格：钱真真1-1100(1).xlsx";
        write(writeFileName, ExcelModel.class).sheet().head(ExcelModel.class)
                .registerWriteHandler(new CustomColumnWidthStrategy())
                .registerWriteHandler(new CustomCellStyleStrategy()).doWrite(dataList);


        String writeFileName2 = "C:\\Users\\hp\\Desktop\\结果单独列出.xlsx";
        write(writeFileName2, ExcelModel.class).sheet().head(ExcelModel.class)
//                .registerWriteHandler(new CustomColumnWidthStrategy())
//                .registerWriteHandler(new CustomCellStyleStrategy())
                .doWrite(singleList);
    }

    public static boolean hasKeyWord(String keyWord){
        return keyWord.contains("发热") || keyWord.contains("寒战") || keyWord.contains("过敏样反应") || keyWord.contains("过敏性休克")
                || keyWord.contains("胸闷") || keyWord.contains("呼吸困难") || keyWord.contains("呼吸急促") || keyWord.contains("哮喘") || keyWord.contains("喉水肿")
                || keyWord.contains("皮疹") || keyWord.contains("瘙痒") || keyWord.contains("剥脱性皮炎")
                || keyWord.contains("心悸") || keyWord.contains("心动过速")
                || keyWord.contains("头晕") || keyWord.contains("头痛") || keyWord.contains("抽搐") || keyWord.contains("震颤")
                || keyWord.contains("恶心") || keyWord.contains("呕吐")
                || keyWord.contains("紫绀") || keyWord.contains("潮红") || keyWord.contains("血压下降") || keyWord.contains("血压升高")
                || keyWord.contains("血尿") || keyWord.contains("肝功能异常")
                ;
    }

    public static void readExcel1100(){
        List<SameModel> sameList = new ArrayList<>();
        List<NotSameModel> notSameList = new ArrayList<>();
        String fileName = "C:\\Users\\hp\\Desktop\\钱多多\\前1100.xls";
        ExcelListener<ComparedModel> excelListener = new ExcelListener<>();
        read(fileName, ComparedModel.class, excelListener).sheet().doRead();
        List<ComparedModel> dataList = excelListener.getDataList();
        List<String> qianduoduo = dataList.stream().map(ComparedModel::getQianduoduo).collect(Collectors.toList());
        List<String> hanfei = dataList.stream().map(ComparedModel::getHanfei).collect(Collectors.toList());
        for (String s : hanfei) {
            if (qianduoduo.contains(s)){
                SameModel sameModel = new SameModel();
                sameModel.setSame(s);
                sameList.add(sameModel);
            } else {
                NotSameModel notSameModel = new NotSameModel();
                notSameModel.setDiff(s);
                notSameList.add(notSameModel);
            }
        }

        List<String> sameStringList = sameList.stream().map(SameModel::getSame).collect(Collectors.toList());
        List<NotSameModel> qianduoduoNotSameList = new ArrayList<>();
        for (String s : qianduoduo){
            if (!sameStringList.contains(s)){
                NotSameModel model = new NotSameModel();
                model.setDiff(s);
                qianduoduoNotSameList.add(model);
            }
        }

        List<NotSameModel> hanfeiNotSameList = new ArrayList<>();
        for (String s : hanfei){
            if (!sameStringList.contains(s)){
                NotSameModel model = new NotSameModel();
                model.setDiff(s);
                hanfeiNotSameList.add(model);
            }
        }

        System.out.println("相同数量："+sameList.size() + ",不同数量："+ notSameList);
//        System.out.println("相同数量："+sameList.size() + ",不同数量："+ notSameList);
//        String writeFileName1 = "C:\\Users\\hp\\Desktop\\钱多多\\相同数据.xls";
//        write(writeFileName1, SameModel.class).sheet().head(SameModel.class)
//                .registerWriteHandler(new CustomColumnWidthStrategy())
//                .registerWriteHandler(new CustomCellStyleStrategy()).doWrite(sameList);

//        String writeFileName2 = "C:\\Users\\hp\\Desktop\\钱多多\\不同数据.xls";
//        write(writeFileName2, NotSameModel.class).sheet().head(NotSameModel.class)
//                .registerWriteHandler(new CustomColumnWidthStrategy())
//                .registerWriteHandler(new CustomCellStyleStrategy()).doWrite(notSameList);

        String writeFileName3 = "C:\\Users\\hp\\Desktop\\钱多多\\钱多多不同数据.xls";
        write(writeFileName3, NotSameModel.class).sheet().head(NotSameModel.class)
                .registerWriteHandler(new CustomColumnWidthStrategy())
                .registerWriteHandler(new CustomCellStyleStrategy()).doWrite(qianduoduoNotSameList);

        String writeFileName4 = "C:\\Users\\hp\\Desktop\\钱多多\\韩飞不同数据.xls";
        write(writeFileName4, NotSameModel.class).sheet().head(NotSameModel.class)
                .registerWriteHandler(new CustomColumnWidthStrategy())
                .registerWriteHandler(new CustomCellStyleStrategy()).doWrite(hanfeiNotSameList);


    }

}
